package gui;
//package ecj;
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.ObjectInputStream;
//
//import opt.FitnessFunction;
//
//import ns2.Topology;
//
//import util.SSIDException;
//
//import ids.Sensor;
//import ids.SensorType;
//
//import ec.EvolutionState;
//import ec.Individual;
//import ec.Problem;
//import ec.simple.SimpleFitness;
//import ec.simple.SimpleProblemForm;
//import ec.util.Parameter;
//import ec.vector.IntegerVectorIndividual;
//
//public class IDSProblemGUI extends Problem implements SimpleProblemForm {
//	private static final long serialVersionUID = 1L;
//
//	private static String SWAP = "swap.dat";
//
//	public static final String SENSORFILE = "sensorFile";
//
//	public Topology topology;
//	public File sensorFile;
//
//	public void setup(EvolutionState state, Parameter base) {
//		// very important, remember this
//		super.setup(state, base);
//
//		// not using a default base here
//		this.sensorFile = new File(state.parameters.getString(base
//				.push(SENSORFILE), null));
//		this.topology = new Topology();
//
//		try {
//			FileInputStream fin = new FileInputStream(SWAP);
//			ObjectInputStream ois = new ObjectInputStream(fin);
//			this.topology = (Topology) ois.readObject();
//			ois.close();
//		} catch (Exception e) {
//			System.err
//					.println("ERROR: cannot unserialize the network topology.");
//		}
//	}
//
//	@Override
//	public void describe(Individual ind, EvolutionState state,
//			int subpopulation, int threadnum, int log, int verbosity) {
//		// TODO Auto-generated method stub
//
//	}
//
//	@Override
//	public void evaluate(EvolutionState state, Individual ind,
//			int subpopulation, int threadnum) {
//		if (ind.evaluated)
//			return;
//
//		if (!(ind instanceof IntegerVectorIndividual))
//			state.output.fatal("Whoa!  It's not a IntegerVectorIndividual!!!",
//					null);
//
//		IntegerVectorIndividual ind2 = (IntegerVectorIndividual) ind;
//		float rawfitness = 0;
//		int numberOfSensors = ind2.genome.length;
//		for (int x = 0; x < ind2.genome.length; x++) {
//			if (ind2.genome[x] < 0)
//				ind2.genome[x] = -ind2.genome[x];
//			ind2.genome[x] = ind2.genome[x] % this.topology.getNumberOfNodes();
//		}
//
//		Sensor[] place = new Sensor[numberOfSensors];
//		for (int i = 0; i < numberOfSensors; i++) {
//			place[i] = Sensor.createSensor(this.sensorType);
//			place[i].setLocation(this.topology.nodes.getNode(ind2.genome[i]));
//			place[i].run();
//		}
//
//		rawfitness = FitnessFunction.evaluate(place);
//
//		if (!(ind2.fitness instanceof SimpleFitness))
//			state.output.fatal("Whoa!  It's not a SimpleFitness!!!", null);
//		((SimpleFitness) ind2.fitness).setFitness(state, rawfitness, false);
//
//		ind2.evaluated = true;
//	}
//
//}
